﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebCalculator
{
    public enum NumericOperation
    {
        Addition,
        Subtraction,
        Multiplication,
        Division,
        SquareRoot,
        Module
    }

    public class Calculator
    {
        private decimal firstOperand;
        private decimal secondOperand;
        private NumericOperation operation;

        public Calculator() { }
        public Calculator(decimal first, decimal second, NumericOperation op)
        {
            FirstOperand = first;
            SecondOperand = second;
            Operation = op;
        }

        public decimal FirstOperand
        {
            get
            {
                return this.firstOperand;
            }
            set
            {
                this.firstOperand = value;
            }
        }

        public Decimal SecondOperand
        {
            get
            {
                return this.secondOperand;
            }
            set
            {
                this.secondOperand = value;
            }
        }

        public NumericOperation Operation
        {
            get
            {
                return this.operation;
            }
            set
            {
                this.operation = value;
            }
        }

        public decimal CalculateResult()
        {
            switch (this.operation)
            {
                case NumericOperation.Addition:
                    return FirstOperand + SecondOperand;

                case NumericOperation.Subtraction:
                    return firstOperand - secondOperand;

                case NumericOperation.Multiplication:
                    return firstOperand * secondOperand;

                case NumericOperation.Division:
                    if (secondOperand == 0)
                    {
                        throw new DivideByZeroException();
                    }
                    return firstOperand / secondOperand;

                case NumericOperation.SquareRoot:
                    return (decimal)Math.Sqrt((double)firstOperand);

                case NumericOperation.Module:
                    return Math.Abs(firstOperand);
            }

            return 0;
        }
    }
}